package clue

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/common/constants"
	cluePb "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/clue"
)

type CustomerManageRepository struct {
}

func NewCustomerManageRepository() CustomerManageRepositoryIface {
	return &CustomerManageRepository{}
}

func (r *CustomerManageRepository) MyResponsibleCustomers(ctx context.Context, request *cluePb.CustomerListRequest) (*cluePb.CustomerListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.MyResponsibleCustomers(ctx, request)
}

func (r *CustomerManageRepository) CustomerList(ctx context.Context, request *cluePb.CustomerListRequest) (*cluePb.CustomerListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.CustomerList(ctx, request)
}

func (r *CustomerManageRepository) CustomerGroupOption(ctx context.Context, request *cluePb.CustomerGroupOptionRequest) (*cluePb.CustomerGroupOptionResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.CustomerGroupOption(ctx, request)
}

func (r *CustomerManageRepository) SaveCustomer(ctx context.Context, request *cluePb.SaveCustomerRequest) (*cluePb.SaveCustomerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.SaveCustomer(ctx, request)
}

func (r *CustomerManageRepository) DeleteCustomer(ctx context.Context, request *cluePb.DeleteCustomerRequest) (*cluePb.DeleteCustomerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.DeleteCustomer(ctx, request)
}

func (r *CustomerManageRepository) ExportCustomerList(ctx context.Context, request *cluePb.CustomerListRequest) (*cluePb.ExportCustomerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ExportCustomerList(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomer(ctx context.Context, request *cluePb.ImportCustomerRequest) (*cluePb.ImportCustomerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomer(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomerList(ctx context.Context, request *cluePb.ImportCustomerListRequest) (*cluePb.ImportCustomerListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomerList(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomerStatus(ctx context.Context, request *cluePb.ImportCustomerStatusRequest) (*cluePb.ImportCustomerStatusResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomerStatus(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomerCount(ctx context.Context, request *cluePb.ImportCustomerCountRequest) (*cluePb.ImportCustomerCountResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomerCount(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomerEdit(ctx context.Context, request *cluePb.ImportCustomerEditRequest) (*cluePb.ImportCustomerEditResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomerEdit(ctx, request)
}

func (r *CustomerManageRepository) ImportCustomerDelete(ctx context.Context, request *cluePb.ImportCustomerDeleteRequest) (*cluePb.ImportCustomerDeleteResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewCustomerManageServiceClient(conn)
	return client.ImportCustomerDelete(ctx, request)
}
